//
//  ObserverTableViewCell.m
//  Rail
//
//  Created by hychen on 2018/3/5.
//  Copyright © 2018年 Hychen. All rights reserved.
//

#import "ObserverTableViewCell.h"
#import "SCPieChart.h"

#define kAllObserverColor Color_RGB(50, 110, 147)
#define kOnlineObserverColor Color_RGB(74, 225, 34)

@interface ObserverTableViewCell ()
@property (weak, nonatomic) IBOutlet UIView *chartView;
@property (weak, nonatomic) IBOutlet UILabel *allLabel;
@property (weak, nonatomic) IBOutlet UILabel *onlineLabel;
@property (weak, nonatomic) IBOutlet UIView *allObserverView;
@property (weak, nonatomic) IBOutlet UIView *onlineObserverView;

@property (nonatomic, strong) SCPieChart *pieChart;
@property (nonatomic, assign) NSInteger allCount;
@property (nonatomic, assign) NSInteger onlineCount;
@end
@implementation ObserverTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self showBottomLineWithPaddingX:15.f color:nil];
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.contentView);
        make.height.mas_equalTo(10);
    }];
    
    WeakSelf_bb
    [self.allObserverView addTapGestureWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        if (weakSelf.BlockClickAllObserver) {
            weakSelf.BlockClickAllObserver();
        }
    }];
    
    [self.onlineObserverView addTapGestureWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        if (weakSelf.BlockClickOnlineObserver) {
            weakSelf.BlockClickOnlineObserver();
        }
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setAllObserverNum:(NSString *)allCount onlineObserverNum:(NSString *)onlineCount {
    self.allLabel.text = allCount;
    self.onlineLabel.text = onlineCount;
    self.allCount = [allCount integerValue];
    self.onlineCount = [onlineCount integerValue];
    [self configPieChart];
}

- (void)configPieChart {
    if (self.pieChart.superview) {
        [self.pieChart removeFromSuperview];
        self.pieChart = nil;
    }
    NSArray *items = @[[SCPieChartDataItem dataItemWithValue:self.allCount color:kAllObserverColor description:@"全部"],
                       [SCPieChartDataItem dataItemWithValue:self.onlineCount color:kOnlineObserverColor description:@"在线"],
                       ];
    
    self.pieChart = [[SCPieChart alloc] initWithFrame:CGRectMake(0, 0, 60.0, 60.0) items:items];
    self.pieChart.showDescValues = NO;
    self.pieChart.descriptionTextColor = kPieChartDescColor;
    self.pieChart.descriptionTextFont  = [UIFont fontWithName:@"Avenir-Medium" size:11.0];
    [self.pieChart strokeChart];
    [self.chartView addSubview:self.pieChart];
    [self.pieChart mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.chartView);
    }];
}

@end
